package member.base.service;

import m.common.service.Service;
import m.system.cache.CacheUtil;
import m.system.exception.MException;
import m.system.util.DateUtil;
import member.base.model.BusinessInfo;
import member.base.util.PowerUtil;

import java.util.Calendar;
import java.util.Date;

public class BusinessInfoService extends Service {

    /**
     * 获取当前时间优惠   0代表无优惠，10代表10%优惠
     */
    public int getDiscount(Date date) throws Exception {
        BusinessInfo setting= PowerUtil.getBusiness();
        if("A".equals(setting.getMemberDayType())&&null!=setting.getMemberDayNo()){
            for(String dayNo : setting.getMemberDayNo()){
                if(dayNo.equals(DateUtil.format(date,"dd"))) {
                    return setting.getDiscount();
                }
            }
        }else if("B".equals(setting.getMemberDayType())){
            int week=DateUtil.get(date, Calendar.DAY_OF_WEEK);
            if(week==Integer.parseInt(setting.getMemberWeekNo())){
                return setting.getDiscount();
            }
        }
        return 0;
    }
    /**
     * 获取当前时间积分倍数  100代表不翻倍，200代表两倍
     */
    public int getPointRate(Date date) throws Exception {
        BusinessInfo setting= PowerUtil.getBusiness();
        if("A".equals(setting.getMemberDayType())&&null!=setting.getMemberDayNo()){
            for(String dayNo : setting.getMemberDayNo()){
                if(dayNo.equals(DateUtil.format(date,"dd"))) {
                    return setting.getDiscount();
                }
            }
        }else if("B".equals(setting.getMemberDayType())){
            int week=DateUtil.get(date, Calendar.DAY_OF_WEEK);
            if(week==Integer.parseInt(setting.getMemberWeekNo())){
                return setting.getPointRate();
            }
        }
        return 100;
    }
}
